﻿using ProjectManager.Logic.Content;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectManager.Interface
{
    /// <summary>
    ///  底层的git操作接口
    ///  使用libgit2sharp包
    ///  用抛出异常的方式，来处理错误
    /// </summary>
    internal interface IGit
    {
        /// <summary>
        /// 克隆远程仓库
        /// 并设置仓库的name和password
        /// 出错则抛出异常
        /// </summary>
        /// <param name="projectInformation">项目信息，包含url和本地path</param>
        /// <param name="name">git用户名</param>
        /// <param name="password">git密码</param>
        void Clone(ProjectInformation projectInformation, string name, string password);
        void Clone(string url, string path, string branchName = "master");
        void CreateBranch(ProjectInformation projectInformation, string branchName);
        void CreateBranch(string repoPath, string branchName);
        /// <summary>
        /// 获取最新版本
        /// 如果有更新，则拉取最新版本，并返回true
        /// 如果没有，则返回false
        /// </summary>
        /// <param name="projectInformation"></param>
        /// <param name="branchName"></param>
        /// <returns></returns>
        bool Pull(ProjectInformation projectInformation,
            ProjectTaskInformation branchInformation);
        void Pull(string repoPath, string branchName
            , string name = "PM", string email = "PM@pm.com");
        void Push(ProjectInformation projectInformation,
            ProjectTaskInformation branchInformation);
        void Push(string repoPath, string branchName);
        void Commit(ProjectInformation projectInformation, 
            ProjectTaskInformation branchInformation, 
            string commitName, string commitDescription);
        void Commit(string repoPath,string branchName,
            string commitName, string commitDescription
            , string name = "PM", string email = "PM@pm.com");
        void Roll(ProjectInformation projectInformation,
            ProjectTaskInformation branchInformation,
            string commitID);
        // 将子分支合并入父分支
        void Merge(ProjectTaskInformation rootTaskInformation, 
            ProjectTaskInformation childTaskInformation);
        // 删除分支
        void DeleteBranch(ProjectTaskInformation childTaskInformation);
        GitCommitTree GetCommitTree(ProjectInformation projectInformation,
            ProjectTaskInformation branchInformation);
        List<string> GetCommitMessages(string repoPath, string branchName);
        // 获取当前提交的位置(主要是commitID)
        GitCommitTree GetCurrentCommitTree(ProjectInformation projectInformation, ProjectTaskInformation branchInformation);
    }
}
